package PhoneLog.PhoneLog2;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

//自定义bean对象就是在很多数据中挑选所需要的的数据进提取出来封装好自己定义的对象里
//自定义bean对象要想序列化传输，必须实现序列化接口，必须实现Writable接口
//alt +enter 实现接口的方法
public class FlowBean implements WritableComparable<FlowBean> {
    private long upFlow;//上行流量
    private long downFlow;//下行流量
    private long sumFlow;//总流量
    private long phoneNum;//手机号
    //反序列化时，需要反射调用空参构造函数，所以必须有空参构造
    public FlowBean() {

    }


    //有参构造器
    public FlowBean(long upFlow, long downFlow, long sumFlow) {

        this.upFlow = upFlow;
        this.downFlow = downFlow;
        this.sumFlow = sumFlow;
        this.phoneNum = phoneNum;
    }
    //setter and getter 方法
    public long getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(long upFlow) {
        this.upFlow = upFlow;
    }

    public long getDownFlow() {
        return downFlow;
    }

    public void setDownFlow(long downFlow) {
        this.downFlow = downFlow;
    }

    public long getSumFlow() {
        return sumFlow;
    }

    public void setSumFlow(long sumFlow) {
        this.sumFlow = sumFlow;
    }

    public long getPhoneNum() {
        return phoneNum;
    }

    public void setPhoneNum(long phoneNum) {
        this.phoneNum = phoneNum;
    }
    //重写toString方法

    @Override
    public String toString() {
        return   upFlow + "\t"+downFlow+"\t"+ sumFlow ;
    }
    //重写序列化方法
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(upFlow);
        out.writeLong(downFlow);
        out.writeLong(sumFlow);
        out.writeLong(phoneNum);
        /* out.writeUTF();//String类型*/
    }
    //重写反序列化方法
    @Override
    public void readFields(DataInput in) throws IOException {
        //反序列化读的顺序要和序列化顺序一致（队列形式先进先出）
        this.upFlow=in.readLong();
        this.downFlow=in.readLong();
        this.sumFlow=in.readLong();
        this.phoneNum=in.readLong();

    }
    //重写比较器的方法
    @Override
    public int compareTo(FlowBean o) {

        return this.upFlow >o.getUpFlow()?-1:1;
    }
}
